package vulnerability

import (
	v1 "github.com/anchore/grype-db/pkg/db/v1"
)

type Metadata struct {
	ID          string
	Severity    string
	Links       []string
	Description string
	CvssV2      *Cvss
	CvssV3      *Cvss
}

type Cvss struct {
	BaseScore           float64
	ExploitabilityScore float64
	ImpactScore         float64
	Vector              string
}

func NewMetadata(m *v1.VulnerabilityMetadata) (*Metadata, error) {
	if m == nil {
		return nil, nil
	}
	return &Metadata{
		ID:          m.ID,
		Severity:    m.Severity,
		Links:       m.Links,
		Description: m.Description,
		CvssV2:      NewCvss(m.CvssV2),
		CvssV3:      NewCvss(m.CvssV3),
	}, nil
}

func NewCvss(m *v1.Cvss) *Cvss {
	if m == nil {
		return nil
	}
	return &Cvss{
		BaseScore:           m.BaseScore,
		ExploitabilityScore: m.ExploitabilityScore,
		ImpactScore:         m.ImpactScore,
		Vector:              m.Vector,
	}
}
